package com.dfrz.service.impl;

import com.dfrz.mapper.IUserMapper;
import com.dfrz.entity.User;
import com.dfrz.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
/**
 * @author 29877
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private IUserMapper iUserMapper;

    @Override
    public User selectUserByid(Integer uid) {
        return iUserMapper.selectById(uid);
    }

    @Override
    public User loginbypwd(String account, String pwd) {
        return iUserMapper.loginbypwd(account,pwd);
    }

    @Override
    public User signin(User user) {
        iUserMapper.adduser(user);
        return iUserMapper.selectById(user.getUid());
    }

    @Override
    public User selectUserbyaccount(String account) {
        return iUserMapper.selectByaccount(account);
    }

    @Override
    public Boolean vip(Integer uid) {
        User u=selectUserByid(uid);
        if(u.getVipStatus()!=1){
            String date=LocalDate.now().plusMonths(1).toString();
            iUserMapper.updatevip(uid,date);
            return true;
        }else {
            String date=LocalDate.parse(u.getVipDate()).plusMonths(1).toString();
            iUserMapper.updatevip(uid,date);
            return true;
        }
    }
    
    @Override
    public List<Object> getUserById(Integer uid) {
        return iUserMapper.getUserById(uid);
    }

}
